﻿using MediatR;
using SlaughterItem.Common.Domains.Check_Ins;
using SlaughterItem.Common.Domains.ListWeek2;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week02.LiveAnimalsa
{
    public class LiveAnimalsShowHandler1 : IRequestHandler<LiveAnimalsShowCommand1, Result>
    {
        IBaseRepositoryGet<LiveAnimals> LiveAnimalsRep;
        IBaseRepositoryGet<CheckIn> CheckInRep;
        IBaseRepositoryGet<Supplier> SupplierRep;
        public LiveAnimalsShowHandler1(IBaseRepositoryGet<LiveAnimals> liveAnimalsRep, IBaseRepositoryGet<CheckIn> checkInRep, IBaseRepositoryGet<Supplier> supplierRep)
        {
            LiveAnimalsRep = liveAnimalsRep;
            CheckInRep = checkInRep;
            SupplierRep = supplierRep;
        }
        /// <summary>
        /// 活畜秤重显示绑定下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<Result> Handle(LiveAnimalsShowCommand1 request, CancellationToken cancellationToken)
        {

            var result = new Result() { Code = (int)CommonErrorCode.Search };
            try
            {
                var list = (from a in LiveAnimalsRep.GetAll()
                            select new
                            {
                                a.LiveAnimalsId,
                                a.LiveAnimalsDocument,
                            }).ToList();
                //如果有数据就返回
                if (list != null)
                {
                    result.Code = (int)CommonErrorCode.Success;
                    result.Data = list;
                    result.Msg = "查询成功";
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
